home *** CD-ROM | disk | FTP | other *** search
- /*
- Get Tool Config
- ©1991 Apple Computer Inc.
- By Apple Developer Tech Support
-
- Description:
- This q&d allows one to accumulate into a TEXT file the config strings
- of Connection Tools that have been configured with CMChoose.
-
- Build Instructions:
- Used with THINK C v5.0, project setup:
- seg1: GetToolConfig.c, MacTraps, CommToolbox
- seg2: ANSI
-
- Change History:
-
- 8/10/91 Godfrey DiGiorgi created this bugger from some existing source lying about
- 8/30/91 Godfrey DiGiorgi fixed it up to be useful
- */
- #include <Traps.h>
- #include <stdio.h>
- #include <CommResources.h>
- #include <Connections.h>
-
- // function prototypes
- void main(void);
-
- void main() {
- short procID;
- ConnHandle connection;
- CMBufferSizes bufSizes;
- OSErr err;
- Str255 toolName;
- Point where;
- short result;
- Ptr configStream;
- FILE* fp;
-
- // putting something into TTY window initializes QD globals, etc.
- printf("•• running Get Tool Config program ••\n\n");
-
- // initialize CTB and managers
- if (NGetTrapAddress(_CommToolboxDispatch, OSTrap) ==
- NGetTrapAddress(_Unimplemented, OSTrap)) {
- printf("•• CTB Not available ••\n");
- return;
- }
- if (noErr != InitCRM()) {
- printf("•• CTB Available but InitCRM failed. ••\n");
- return;
- }
- if (noErr != InitCTBUtilities()) {
- printf("•• CTB Available: InitCTBUtilities Fail. ••\n");
- return;
- }
- if (cmNoTools == InitCM()) {
- printf("•• CTB Available: No connection tools found. ••\n");
- return;
- }
-
- // get a Connection Tool name
- err = CRMGetIndToolName('cbnd',1,toolName);
- if (err != noErr) {
- printf("•• CRMGetIndToolName failed... no Conn Tool available ?!?!? ••\n");
- return;
- }
- // get a resource ID for it
- procID = CMGetProcID(toolName);
- if (-1 == procID) {
- printf("•• CMGetProcID: No 'Apple (ISDN) Serial Tool'. ••\n");
- return;
- }
-
- // init the CMBufferSizes variable so that Tool will init with defaults
- bufSizes[cmDataIn] = 0;
- bufSizes[cmDataOut] = 0;
- bufSizes[cmCntlIn] = 0;
- bufSizes[cmCntlOut] = 0;
- bufSizes[cmAttnIn] = 0;
- bufSizes[cmAttnOut] = 0;
-
- // now get a conn record set up
- connection = CMNew(procID, cmData|cmNoMenus|cmQuiet, bufSizes, 0, 0);
- if (connection == nil) {
- printf("•• CMNew: Can't create a CTB connection record. ••\n");
- return;
- }
-
- // CMChoose Dialog has to hang off this point (global coordinates)
- SetPt(&where,20,40);
- // now do CMChoose et al:
- result = CMChoose(&connection,where,NULL);
- if ((result == chooseOKMajor) || (result == chooseOKMinor)) {
- configStream = CMGetConfig(connection);
- if (configStream == NULL) {
- printf("CMGetConfig failed\n\n");
- } else {
- CMGetToolName((**connection).procID,toolName);
- PtoCstr(toolName);
- printf("• Configuration string for %s:\n'%s'\n\n",toolName, configStream);
- fp = fopen("Tool Configs","a");
- if (fp != NULL) {
- fprintf(fp,"• Configuration string for %s:\n'%s'\n\n",toolName, configStream);
- fclose(fp);
- printf("•• Configuration string info appended to file 'Tool Configs'. ••\n\n");
- } else {
- printf("•• Output file could not be opened. ••\n");
- }
- DisposPtr(configStream);
- }
- } else {
- printf("•• CMChoose failed. ••\n");
- }
- CMDispose(connection);
- printf("•• closing Get Tool Config program ••\n\n");
- }
-